﻿using System;
using Coding4Fun.Phone.Controls;

namespace FinalCountdown.Controls
{
    public class Prompt
    {
        private readonly Action _callbackOnCancel;
        private readonly Action _callbackOnOk;
        private readonly string _title;

        public Prompt(string title, Action callbackOnOk, Action callbackOnCancel = null)
        {
            _title = title;
            _callbackOnOk = callbackOnOk;
            _callbackOnCancel = callbackOnCancel;
        }

        public PopUpResult LastResult { get; set; }

        public void Show()
        {
            var messagePrompt = new MessagePrompt { IsCancelVisible = true, Title = _title };

            messagePrompt.Completed += (s, e) =>
            {
                LastResult = e.PopUpResult;
                if (e.PopUpResult == PopUpResult.Ok)
                {
                    _callbackOnOk.Invoke();
                }
                else
                {
                    if (_callbackOnCancel != null)
                    {
                        _callbackOnCancel.Invoke();
                    }
                }
            };
            messagePrompt.Show();
        }
    }
}
